How to detect screen touches in a simple way
In your Java class, do the following:
package JAVARuntime;
public class YourClass extends Component {
@Override
public void start() {
}
@Override
public void repeat() {
if(Input.getTouch(0).isDown()) {
// your code
}
}
}
Understanding the code
- The
0
argument of thegetTouch()
method is equivalent to the first touch on the screen, and follows this reasoning for the second touch, third...
For example
Input.getTouch(1).isDown()... // detects the second touch on the screen
Input.getTouch(2).isDown()... // detects the third touch on the screen
...
isDown()
- Detects touch when the screen is touched.
isUp()
- Detects touch when the screen is released.
isPressed()
- Detects touch while the screen is being pressed.